Compute primes using sieve of eratosthenes methodΒΆ
Write a python program using sieve of eratosthenes method for computing
primes upto a specified number.
Note: In mathematics, the sieve of Eratosthenes, (Ancient Greek: koskinon Eratosthenous)
one of a number of prime number sieves, is a simple, ancient algorithm for finding all
prime numbers up to any given limit.
def prime_eratosthenes(N):
prime_list = []
for i in range(2, N+1):
if i not in prime_list:
print (i)
for j in range(i * i, N + 1, i):
prime_list.append(j)
# test
print(prime_eratosthenes(100))
Output:
2
3
5
7
11
...
79
83
89
97
None